﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace WPNextTools.NBase
{
    public class SuspendableObject
    {
        private byte suspendCount;

        public bool IsSuspended
        {
            get
            {
                return suspendCount > 0;
            }
        }
        /// <summary>
        /// 阻断
        /// </summary>
        public void Suspend()
        {
            this.suspendCount += 1;
            if (this.suspendCount == 1)
            {
                this.SuspendOverride();
            }
        }
        /// <summary>
        /// 复苏
        /// </summary>
        public void Resume()
        {
            this.Resume(true);
        }

        public void Resume(bool update)
        {
            if (this.suspendCount == 0)
            {
                return;
            }
            this.suspendCount -= 1;
            if (this.suspendCount == 0)
            {
                this.OnResume(update);
            }
        }

        protected virtual void SuspendOverride()
        {
            
        }

        protected virtual void OnResume(bool update)
        {

        }
    }
}
